package cn.wolfcode.crm.service.impl;

import cn.wolfcode.crm.domain.Department;
import cn.wolfcode.crm.mapper.DepartmentMapper;
import cn.wolfcode.crm.query.QueryObject;
import cn.wolfcode.crm.service.IDepartmentService;
import cn.wolfcode.crm.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

@Service
public class DepartmentServiceImpl implements IDepartmentService {
    @Autowired
    private DepartmentMapper mapper;

    public List<Department> selectAll() {
        return mapper.selectAll();
    }

    public PageResult query(QueryObject qo) {
        int count = mapper.query4Count(qo);
        if (count > 0) {
            return new PageResult(count, mapper.query4List(qo));
        }
        return new PageResult(count, Collections.EMPTY_LIST);
    }

    public void updateByPrimaryKey(Department record) {
        mapper.updateByPrimaryKey(record);
    }

    public Department getByName(String name) {
        return mapper.getByName(name);
    }

    public void insert(Department record) {
        mapper.insert(record);
    }

    public void changeState(Long id) {
        mapper.changeState(id);
    }

    public Long selectByUserName(String name) {
        return mapper.selectByUserName(name);
    }

    public Department selectByPrimaryKey(Long id) {
        return mapper.selectByPrimaryKey(id);
    }


}
